package ShuZu;

import javax.xml.transform.Result;
import java.util.Arrays;

public class ForEach {
    public static void main(String[] args) {
        int[] a = {1, 2, 3, 4, 5};
        //没有下标 方便遍历输出
//        for (int i : a) {
//            System.out.print(i);
//        }
        int[] b = reverse(a);
        printArray(b);
    }

    //打印数组
    public static void printArray(int[] arrays) {
        for (int i = 0; i < arrays.length; i++) {
            System.out.print(arrays[i]+" ");
        }
    }

    //反转数组 1,2,3,4,5 变成 5,4,3,2,1
    public static int[] reverse(int[] a) {
        int[] result = new int[a.length];
        for (int i = 0, j = a.length - 1; i < a.length; i++, j--) {
            result[j] = a[i];
        }
        return result;
    }
}
